#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    // 请在此输入您的代码
    int N, V;
    cin >> N >> V;
    vector<int> w(N + 1), v(N + 1), s(N + 1);
    for (int i = 1;i <= N;i++)
    {
        cin >> w[i] >> v[i] >> s[i];
    }
    vector<int> dp(V + 1, 0);
    for (int i = 1;i <= N;i++)
    {
        for (int j = V;j >= w[i];j--)
        {
            for (int k = 1;k <= s[i] && k * w[i] <= j;k++)
            {
                dp[j] = max(dp[j - w[i] * k] + k * v[i], dp[j]);
            }
        }
    }
    cout << dp[V] << endl;
    return 0;
}